package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.GuestsDriver;
import com.yh.homestay.service.GuestsDriverService;
import com.yh.homestay.common.QiNiuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GuestsDriverController
 * @Description 司机Controller
 * @Date 2020/1/13 16:23
 */
@RestController
@Api(description = "司机管理")
@RequestMapping(value = "/driver")
public class GuestsDriverController {

    @Autowired
    private GuestsDriverService driverService;

    /**
     * @param page
     * @param limit
     * @param driverName
     * @Date: 2020/1/14 17:26
     * @Description: 获取所有司机列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "司机列表", module = "司机管理")
    @ApiOperation(value = "获取所有司机列表", notes = "获取所有司机信息或者模糊查询")
    public HomeStayResult selectAll(Integer page, Integer limit, String driverName) {
        return driverService.showDriver(page, limit, driverName);
    }

    /**
     * @param guestsDriver
     * @Date: 2020/1/14 17:26
     * @Description: 添加司机
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SystemLog(methods = "添加司机", module = "司机管理")
    @ApiOperation(value = "添加司机", notes = "添加司机信息")
    public HomeStayResult addDriver(GuestsDriver guestsDriver) {
        guestsDriver.setDriverDrivingPic(QiNiuUtil.qiniu_img_url_pre + guestsDriver.getDriverDrivingPic());
        guestsDriver.setDriverIdcardA(QiNiuUtil.qiniu_img_url_pre + guestsDriver.getDriverIdcardA());
        guestsDriver.setDriverIdcardB(QiNiuUtil.qiniu_img_url_pre + guestsDriver.getDriverIdcardB());
        return driverService.insertDriver(guestsDriver);
    }

    /**
     * @param id
     * @Date: 2020/1/14 17:26
     * @Description: 回显司机信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/one/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "回显司机信息", notes = "回显司机信息")
    public HomeStayResult editDriver(@PathVariable Integer id) {
        return driverService.selectOneDriver(id);
    }

    /**
     * @param driver
     * @Date: 2020/1/14 17:26
     * @Description: 修改司机信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SystemLog(methods = "修改司机信息", module = "司机管理")
    @ApiOperation(value = "修改司机信息", notes = "修改司机信息")
    public HomeStayResult editDriver(GuestsDriver driver) {
        return driverService.updateDriver(driver);
    }

    /**
     * @param driverId
     * @Date: 2020/1/14 17:27
     * @Description: 删除司机
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @SystemLog(methods = "删除司机", module = "司机管理")
    @ApiOperation(value = "删除司机", notes = "删除司机信息")
    public HomeStayResult deleteById(Integer driverId) {
        return driverService.deleteDriver(driverId);
    }

    /**
     * @param ids
     * @Date: 2020/1/14 17:27
     * @Description: 批量删除司机
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个司机", module = "司机管理")
    @ApiOperation(value = "批量删除司机", notes = "批量删除司机信息")
    public HomeStayResult deleteSelectDriver(@RequestParam List<Integer> ids) {
        return driverService.deleteBatchDriver(ids);
    }

}

